Skip to content

feat: restore working tree when release fails locally#205

Merged
AlCalzone merged 7 commits into
masterfrom
rollback-neo
May 6, 2026
Merged

feat: restore working tree when release fails locally#205
AlCalzone merged 7 commits into
masterfrom
rollback-neo

Conversation

@AlCalzone

Copy link
Copy Markdown
Owner

supersedes: #118

@AlCalzone AlCalzone requested a review from Copilot May 6, 2026 07:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a rollback mechanism that restores the local git working tree (and related git objects) when a release fails locally, and adds a --no-rollback escape hatch. It integrates rollback snapshotting into stage execution and finalizes rollback after the release run ends.

Changes:

  • Add rollback snapshot + finalize lifecycle in @alcalzone/release-script-core (stash snapshot, HEAD reset, optional tag deletion, untracked cleanup).
  • Wire rollback into execution flow: snapshot before first mutating stage; finalize rollback at the end of the CLI run.
  • Track git-side rollback state in the git plugin (created tag and whether push was attempted), with added tests.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/release-script/src/index.ts Adds --noRollback option and ensures rollback finalization runs before exiting on failures.
packages/plugin-git/src/index.ts Records created tag for safe deletion and marks when push begins to disable rollback after remote interaction.
packages/plugin-git/src/index.test.ts Adds tests around rollback.pushAttempted behavior in push stage.
packages/core/src/types.ts Exports RollbackState type from core types.
packages/core/src/lib/rollback.ts Implements rollback snapshotting and finalization logic using git commands and stash bookkeeping.
packages/core/src/lib/rollback.test.ts Adds unit tests for rollback snapshot/finalize behavior.
packages/core/src/lib/planner.ts Captures rollback snapshot before the first non-check stage executes.
packages/core/src/lib/context.ts Extends Context with optional rollback state and defines RollbackState.
packages/core/src/index.ts Exports rollback functions from core public API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/plugin-git/src/index.ts Outdated
Comment thread packages/core/src/lib/planner.ts Outdated
Comment thread packages/core/src/lib/rollback.ts
Comment thread packages/core/src/lib/rollback.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comment thread packages/core/src/lib/rollback.ts Outdated
Comment thread packages/core/src/lib/rollback.ts
Comment thread packages/core/src/lib/rollback.ts Outdated
Comment thread packages/release-script/src/index.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Comment thread packages/core/src/lib/rollback.ts Outdated
Comment thread packages/core/src/lib/rollback.ts Outdated
Comment thread packages/release-script/src/index.ts
Comment thread packages/core/src/lib/rollback.test.ts Outdated
Comment thread packages/core/src/lib/rollback.test.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Comment thread packages/core/src/lib/rollback.ts Outdated
Comment on lines +100 to +103
context.cli.warn(
`Failed to snapshot uncommitted changes for rollback: ${e?.message ?? e}. ` +
`Rollback will undo committed and edited files but cannot restore ` +
`untracked files; cleanup of untracked files will be skipped.`,
Comment thread packages/core/src/lib/context.ts Outdated

/**
* State used to roll back local changes if the release fails.
* Populated by `captureRollbackSnapshot` once the edit stage is about to run.
Comment thread packages/core/src/lib/rollback.ts Outdated
Comment on lines +70 to +80
// Conservatively treat the tree as dirty so rollback won't run a
// destructive `git clean` against state we couldn't observe.
context.cli.warn(
`Could not determine working tree status for rollback: ${e?.message ?? e}. ` +
`Rollback will skip cleanup of untracked files to avoid data loss.`,
);
context.rollback = {
originalHead,
pushAttempted: false,
cleanAllowedDuringRollback: false,
};

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comment thread packages/plugin-git/src/index.test.ts Outdated
context.rollback = {
originalHead: "deadbeef",
pushAttempted: false,
cleanAllowedDuringRollback: true,
Comment on lines +466 to +470
context.rollback = {
originalHead: "deadbeef",
pushAttempted: false,
cleanAllowedDuringRollback: true,
};
Comment on lines +490 to +494
context.rollback = {
originalHead: "deadbeef",
pushAttempted: false,
cleanAllowedDuringRollback: true,
};
Comment on lines +509 to +513
context.rollback = {
originalHead: "deadbeef",
pushAttempted: false,
cleanAllowedDuringRollback: true,
};

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@AlCalzone AlCalzone merged commit c5235e1 into master May 6, 2026
12 checks passed
@AlCalzone AlCalzone deleted the rollback-neo branch May 6, 2026 21:34
AlCalzone added a commit that referenced this pull request May 6, 2026
* Local changes are now snapshotted and restored if the release fails locally (#205)
* Fix: make `CHANGELOG_OLD.md` rotation more resilient (#202)
AlCalzone added a commit that referenced this pull request May 6, 2026
* Local changes are now snapshotted and restored if the release fails locally (#205)
* Fix: make `CHANGELOG_OLD.md` rotation more resilient (#202)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants